| Conditions | 13 |
| Paths | 13 |
| Total Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like $.fn.symphonySelectable often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /** |
||
| 47 | objects.on('click.selectable', settings.items, function select(event) { |
||
| 48 | var item = $(this), |
||
| 49 | items = item.siblings().addBack(), |
||
| 50 | object = $(event.liveFired), |
||
| 51 | target = $(event.target), |
||
| 52 | selection, deselection, first, last; |
||
| 53 | |||
| 54 | // Ignored elements |
||
| 55 | if(target.is(settings.ignore)) { |
||
| 56 | return true; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Remove text ranges |
||
| 60 | if(window.getSelection) { |
||
| 61 | window.getSelection().removeAllRanges(); |
||
| 62 | } |
||
| 63 | |||
| 64 | // Range selection |
||
| 65 | if((event.shiftKey) && items.filter('.selected').length > 0 && !object.is('.single')) { |
||
| 66 | |||
| 67 | // Select upwards |
||
| 68 | if(item.prevAll().filter('.selected').length > 0) { |
||
| 69 | first = items.filter('.selected:first').index(); |
||
| 70 | last = item.index() + 1; |
||
| 71 | } |
||
| 72 | |||
| 73 | // Select downwards |
||
| 74 | else { |
||
| 75 | first = item.index(); |
||
| 76 | last = items.filter('.selected:last').index() + 1; |
||
| 77 | } |
||
| 78 | |||
| 79 | // Get selection |
||
| 80 | selection = items.slice(first, last); |
||
| 81 | |||
| 82 | // Deselect items outside the selection range |
||
| 83 | deselection = items.filter('.selected').not(selection).removeClass('selected').trigger('deselect.selectable'); |
||
| 84 | deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false); |
||
| 85 | |||
| 86 | // Select range |
||
| 87 | selection.addClass('selected').trigger('select.selectable'); |
||
| 88 | selection.find('input[type="checkbox"]:hidden:first').prop('checked', true); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Single selection |
||
| 92 | else { |
||
| 93 | |||
| 94 | // Press meta or ctrl key to adjust current range, otherwise the selection will be removed |
||
| 95 | if((!event.metaKey && !event.ctrlKey && settings.mode != 'additive' && !target.is('input')) || object.is('.single')) { |
||
| 96 | deselection = items.not(item).filter('.selected').removeClass('selected').trigger('deselect.selectable'); |
||
| 97 | deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false); |
||
| 98 | } |
||
| 99 | |||
| 100 | // Toggle selection |
||
| 101 | if(item.is('.selected')) { |
||
| 102 | item.removeClass('selected').trigger('deselect.selectable'); |
||
| 103 | item.find('input[type="checkbox"]:hidden:first').prop('checked', false); |
||
| 104 | } |
||
| 105 | else { |
||
| 106 | item.addClass('selected').trigger('select.selectable'); |
||
| 107 | item.find('input[type="checkbox"]:hidden:first').prop('checked', true); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | }); |
||
| 112 | |||
| 131 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.